// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUi from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import store from './store'

import {postRequest} from "./utils/api";
import {deleteRequest} from "./utils/api";
import {putRequest} from "./utils/api";
import {getRequest} from "./utils/api";
//以插件形式使用封装的请求接口
Vue.prototype.postRequest=postRequest;
Vue.prototype.putRequest=putRequest;
Vue.prototype.getRequest=getRequest;
Vue.prototype.deleteRequest=deleteRequest;

import {datetime2string} from "./utils/utils";
Vue.prototype.datetime2string=datetime2string;

Vue.use(ElementUi);
Vue.use(router);
Vue.config.productionTip = false;

//路由导航守卫
router.beforeEach((to, from, next) => {
  const role = sessionStorage.getItem('currentUser');
  if (to.path === '/backSchool' || to.path === '/searchAlumni') {
    if(role){
      next();
    }else{
      if (to.path === '/backSchool'){
        sessionStorage.setItem('preRoute', '/backSchool');
      }else{
        sessionStorage.setItem('preRoute', '/searchAlumni');
      }
      ElementUi.Message({
        message: '使用此功能需要登陆，请先登录系统!',
        type: 'error'
      });
      next('/login');
    }
  } else {
    next();
  }
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
});
